package com.td.core.messages;

import com.td.core.communication.Sendable;

public class TDMessage implements Sendable<TDMessage>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	int timeLeft;
	
	String text;
	
	public TDMessage(String text) {
		this.text = text;
		this.timeLeft = 40;
	}
	
	public TDMessage(TDMessage tdm) {
		this.text = tdm.text;
		this.timeLeft = tdm.timeLeft;
	}
	
	public boolean update() {
		
		if(--timeLeft <= 0)
			return false;
		return true;
	}
	
	@Override
	public void copyTo(TDMessage obj) {
		synchronized (obj) {
			obj.text = this.text;
			obj.timeLeft = this.timeLeft;
		}
	}

	@Override
	public TDMessage getCopy() {		
		return new TDMessage(this);
	}

	public String getText() {
		return text;
	}	
}
